package sdk.wufun.com.wfsdk_ysdk4switchpay;

import android.app.Activity;
import android.util.Log;

import com.wufun.pay.plug.wufunpaylib.WufunPayCenter;
import com.wufun.pay.plug.wufunpaylib.paytype.CheckPayTypeRequest;
import com.wufun.pay.plug.wufunpaylib.paytype.CheckResponse;
import com.wufun.pay.plug.wufunpaylib.paytype.PayTypeListener;
import com.wufun.pay.plug.wufunpaylib.paytype.YSdkPayConfigDto;
import com.wufun.sdk.IPay;
import com.wufun.sdk.PayParams;
import com.wufun.sdk.WFSDK;

public class YSDKPay implements IPay {

	public YSDKPay(Activity context){
		
	}
	
	@Override
	public boolean isSupportMethod(String methodName) {

		return true;
	}

	@Override
	public void pay(final PayParams data) {
		WufunPayCenter.init(WFSDK.getInstance().getContext(), "16002160", "4025ec08956708bc");

		CheckPayTypeRequest request = new CheckPayTypeRequest(WFSDK.getInstance().getAppID()+"", WFSDK.getInstance().getCurrChannel()+"", "0", data.getExtension(), WFSDK.getInstance().getWFToken().getUserID()+"", WFSDK.getInstance().getWFToken().getToken()+"", "1", data.getPrice()*100+"",WFSDK.getInstance().getAppKey());

		Log.d("WFSDK", "ready to get paytype:url ="+WFSDK.getInstance().getWFServerURL()+";appid="+WFSDK.getInstance().getAppID()+";channel="+WFSDK.getInstance().getCurrChannel()+";uid="+WFSDK.getInstance().getWFToken().getUserID()+";token="+WFSDK.getInstance().getWFToken().getToken()+";extension="+data.getExtension()+";cpOrderId="+data.getCpOrderID());
		WufunPayCenter.getPayType(WFSDK.getInstance().getWFServerURL(), request, new PayTypeListener() {
			@Override
			public void onGetPayType(CheckResponse<YSdkPayConfigDto> dtoCheckResponse) {
				Log.d("WFSDK", "onGetPayType result="+dtoCheckResponse.getState());
				if (dtoCheckResponse.getState() == 1) {
					YSdkPayConfigDto ySdkPayConfigDto = dtoCheckResponse.getData();
					Log.d("WFSDK", "ySdkPayConfigDto.isUseWF()="+ySdkPayConfigDto.isUseWF()+";notify="+ySdkPayConfigDto.getNotifyURL());
					if(ySdkPayConfigDto.isUseWF()){
						YSDK.payByWF(data,ySdkPayConfigDto.getNotifyURL(),ySdkPayConfigDto.getDiscount(),ySdkPayConfigDto.getDiscountAmount());
					}else {
						YSDK.pay(data);
					}
//					ToastUtils.getInstance(WFSDK.getInstance().getContext()).showToastSystem(" NotifyURL= " + ySdkPayConfigDto.getNotifyURL() + ", sUseWF= " + ySdkPayConfigDto.isUseWF());

				}else {
					YSDK.pay(data);
				}
			}
		});



	}

}
